<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../rest.css">
    <style>
        .wrap {
            margin: 50px auto;
            border: 1px black solid;
            width: 800px;
        }

        .top {
            background: aqua;
            border: 1px gray solid;
            width: 100%;
            height: 300px;
        }

        .bottom {
            background: aquamarine;
            width: 100%;
            height: 100px;
            margin-top: 50px;
            position: relative;
        }

        .box {
            background: yellow;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="top"></div>
        <div class="bottom">
            <div class="box"></div>
        </div>
    </div>
</body>
<script>
    var box = document.getElementsByClassName('box')[0]
    var bottom = document.getElementsByClassName('bottom')[0]
    box.onmousedown = function (e) {
        var e = e || window.event
        var oriX = e.pageX - box.offsetLeft
        bottom.onmousemove = function (e) {
            var e = e || window.event
            var chaX = e.pageX - oriX
            var maxChaX=bottom.clientWidth - box.clientWidth
            chaX = Math.min(Math.max(chaX, 0),maxChaX)
            box.style.left = chaX + 'px'
            if (box.offsetLeft >= 700) {
                location.href='http://www.baidu.com'
            }
        }
        bottom.onmouseup = function () {
            bottom.onmousemove = null
            box.style.left = 0
        }
    }


</script>

</html>